package com.freedy.dataStructure.sort;

import java.util.Arrays;

/**
 * @author Freedy
 * @date 2021/3/18 20:47
 */
public class InsertionSort {
    public static void main(String[] args) {
        //20个随机数
        int[] arr={368,93,284,507,204,620,331,573,910,977,
                711,305,825,438,698,49,868,241,598,737};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void sort(int[] arr){
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < i+1; j++) {
                if (arr[j]>arr[i+1]){
                    int temp=arr[i+1];
                    System.arraycopy(arr, j, arr, j + 1, i + 1 - j);
                    arr[j]=temp;
                }
            }
        }
    }
    
}
